package com.qire.manhua.dialog;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;

import com.qire.antsrouter.AntsRouter;
import com.qire.antsrouter.card.FloorCard;
import com.qire.common.constant.Navigation;
import com.qire.common.support.base.BaseDialog;
import com.qire.manhua.R;
import com.qire.manhua.databinding.DialogSpecialEventBinding;
import com.qire.manhua.model.entity.ComicBookEntity;
import com.qire.common.model.enumeration.SpecialEventType;

import androidx.annotation.NonNull;
import androidx.databinding.ObservableField;

/**
 * 特殊活动弹窗（首页推广活动、支付购买后活动提示等）
 */
public class SpecialEventDialog extends BaseDialog {

    private final DialogSpecialEventBinding binding;

    private final ObservableField<String> imagePath = new ObservableField<>("");

    private String eventUrl, eventTitle;
    private ComicBookEntity comicBookEntity;
    private SpecialEventType eventType = SpecialEventType.WebLinkPage;

    public SpecialEventDialog(@NonNull Context context) {
        super(context, R.style.CustomDialog_Translucent);
        LayoutInflater inflater = LayoutInflater.from(context);
        binding = DialogSpecialEventBinding.inflate(inflater);
        binding.setSpecialEventDialog(this);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(binding.getRoot());
    }

    public SpecialEventDialog setEventInfo(String eventUrl, String eventTitle) {
        return setEventInfo(null, null, eventUrl, eventTitle);
    }
    public SpecialEventDialog setEventInfo(SpecialEventType eventType, ComicBookEntity comicBookEntity, String eventUrl, String eventTitle) {

        if(eventType != null)
            this.eventType = eventType;
        if(comicBookEntity != null)
            this.comicBookEntity = comicBookEntity;

        this.eventUrl   = eventUrl;
        this.eventTitle = eventTitle;
        return this;
    }
    public SpecialEventDialog setImagePath(String imagePath) {
        this.imagePath.set(imagePath);
        return this;
    }

    public ObservableField<String> getImagePath() {
        return imagePath;
    }

    public void imageViewOnClick(View view) {
        switch (eventType){
            case WebLinkPage:
                AntsRouter.ROUTER.<FloorCard>buildCard(Navigation.Page.WebPage)
                        .withData("url", eventUrl)
                        .withData("title", eventTitle)
                        .navigation();

                break;
            case ComicReadPage:
                AntsRouter.ROUTER.<FloorCard>buildCard(Navigation.Page.ComicReaderPage)
                        .withData("comicBookEntity", comicBookEntity)
                        .navigation();
                break;
        }
        dismiss();
    }

    public void closeBtnOnClick(View view){
        dismiss();
    }


}
